import { macro, SystemEvent, systemEvent } from "cc"



export class Input  {
    private static instance:Input =null

	x:number = 0
	y:number = 0

	static get Instance(){
		if(this.instance==null){
			this.instance = new Input()
		}
		return this.instance
	}

	constructor(){
		systemEvent.on(SystemEvent.EventType.KEY_DOWN,(e)=>{
			if(e.keyCode==macro.KEY.w){
				this.y = 1
			}
			if(e.keyCode==macro.KEY.s){
				this.y = -1
			}
			if(e.keyCode==macro.KEY.a){
				this.x = -1
			}
			if(e.keyCode==macro.KEY.d){
				this.x = 1
			}
		})

		systemEvent.on(SystemEvent.EventType.KEY_UP,(e)=>{
			if(e.keyCode==macro.KEY.w && this.y == 1){
				this.y = 0
			}
			if(e.keyCode==macro.KEY.s && this.y == -1){
				this.y = 0
			}
			if(e.keyCode==macro.KEY.a && this.x == -1){
				this.x = 0
			}
			if(e.keyCode==macro.KEY.d && this.x == 1){
				this.x = 0
			}
		})
	}
}

